import React, {useState} from 'react';
import {Input, Affix} from 'antd';
import { SearchOutlined } from '@ant-design/icons';
import style from './input.module.css'
import { throttle } from '../../utils/throttle';
import {withRouter} from "react-router-dom";
const MyInput = (props) => {
    const [content,setContent]=useState([])
    // 节流函数 一秒发一次
    // const delay = 1000
    const inputChangeFunc = (e) => {
        setContent(e.target.value)
    }
    const search=async ()=>{
        const token =localStorage.getItem('TOKEN')
        if(token)
        props.history.push('/index/search', {keyWord:content});
        else
            props.history.push('/visit/search',{keyWord:content})
        setContent("")
    }
    return (
        <Affix offsetTop={props.size} >
            <div className={`${style.body}`}>
                <Input placeholder="search some share "
                        className={style.radius}
                        onPressEnter={search}
                        value={content}
                        // onChange={throttle(inputChangeFunc, props.delay)}
                       onChange={(event)=>inputChangeFunc(event)}
                       prefix={<SearchOutlined />} />
            </div>
        </Affix>
    )
}

export default withRouter(MyInput);
